package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Products;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.mapper.ProductsMapper;
import com.by.query.ProductQuery;
import com.by.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@Api(tags = "产品管理")
public class ProductController extends BaseController {

    @Autowired
    ProductService productService;
    @Autowired
    ProductsMapper productsMapper;

    @ApiOperation("产品列表")
    @PostMapping("/product")
    public ResultBean query(@RequestBody ProductQuery query) {
        PageBean pageBean = productService.queryByMap(BeanUtil.beanToMap(query));
        return success("产品列表", pageBean);
    }
    @ApiOperation("保存产品信息")
    @PostMapping("/product/save")
    public ResultBean save(@RequestBody Products product) {
        int save = productsMapper.save(product);
        return success("产品列表", save);
    }

}
